from common.b_yamlOperate import *

envData = YamlRead(pathConf.get_userFilePath("data/a_envData/env.yaml"))

class mrjbus():
    """
    与美人计业务逻辑相关的公共方法
    """
    def __init__(self):
        self.run_type = envData.getdata()['run_type']

    def choiseToken(self):
        """
        根据运行环境选择用户
        """
        if self.run_type == 0:
            data = YamlRead(pathConf.get_userFilePath("data/a_envData/testUser.yaml"))
            tokens = data.getdata()
            return tokens
        elif self.run_type == 1:
            data = YamlRead(pathConf.get_userFilePath("data/a_envData/prodUser.yaml"))
            tokens = data.getdata()
            return tokens

    def getSaleUser(self):
        """
        根据测试环境获取经销商用户user_id
        """
        if self.run_type == 0:
            data = YamlRead(pathConf.get_userFilePath("data/a_envData/testUser.yaml"))
            user_id = data.getdata()['sale_user']
            return user_id
        elif self.run_type == 1:
            data = YamlRead(pathConf.get_userFilePath("data/a_envData/prodUser.yaml"))
            user_id = data.getdata()['sale_user']
            return user_id

    def DefaultUser(self):
        """
        获取默认用户，默认以配置的第一个用户作为默认用户
        """
        data = self.choiseToken()['users'][0]
        return data

    def DefaultSpuId(self,spuId=None):
        """
        获取默认商品ID
        """
        if spuId == None:
            if self.run_type == 0:
                data = envData.getdata()['test_spuId']
                return data[0]
            elif self.run_type == 1:
                data = envData.getdata()['prod_spuId']
                return data[0]
        else:
            spuId = spuId
            return spuId


    def getBrandId(self):
        """
        根据测试环境获取品牌id
        home_brand 在该表获取
        """
        run_type = envData.getdata()['run_type']
        if run_type == 0:
            BrandList = [1,2,1018,1021,1022]
            return BrandList
        elif run_type == 1:
            BrandList = [2000, 2001, 2002, 2003, 2004,2005]
            return BrandList

    def getSpuId(self):
        """
        根据测试环境获取商品Id
        """
        run_type = envData.getdata()['run_type']
        if run_type == 0:
            spuId = envData.getdata()['test_spuId']
            return spuId
        elif run_type == 1:
            spuId = envData.getdata()['prod_spuId']
            return spuId

    def getSelectSpuKW(self):
        """
        根据测试环境获取搜索商品的关键字
        """
        run_type = envData.getdata()['run_type']
        if run_type == 0:
            spuKW = envData.getdata()['test_selectSpuKW']
            return spuKW
        elif run_type == 1:
            spuKW = envData.getdata()['prod_selectSpuKW']
            return spuKW



mrjbusC = mrjbus()


if __name__ == "__main__":
    pass
    # print(mrjbusC.getSaleUser())